<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
  <div class="body-content">
    <form method="post" enctype="multipart/form-data" action="/workview/superviseadd1" id="form-x" class="form-x" >

      <div class="form-group">
        <div class="label">
          <label>请输入工号：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="tno" id="tno" data-validate="required:请输入工号长度11位" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>

      <div class="form-group">
        <div class="label">
          <label>请输入密码：</label>
        </div>
        <div class="field">
          <input type="password" class="input w50" value="" name="password" id="password" data-validate="required:请输入工号" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>
		
		<div class="form-group">
		  <div class="label">
		    <label>再次输入密码：</label>
		  </div>
		  <div class="field">
		    <input type="password" class="input w50" value="" name="password1" id="password1" data-validate="required:请输入工号" />
		    <span style="margin-left: 10px; color: red;">*</span>
		    <div class="tips"> </div>
		  </div>
		</div>

      <div class="form-group">
        <div class="label">
          <label>添加姓名：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="name" id="name" data-validate="required:请输入添加人的姓名" />
          <span style="margin-left: 10px; color: red;">*</span>
          <div class="tips"> </div>
        </div>
      </div>
	  
	  <div class="form-group">
	    <div class="label">
	      <label>添加职称：</label>
	    </div>
	    <div class="field">
	      <input type="text" class="input w50" value="" name="professional" id="professional" />
	      <div class="tips"> </div>
	    </div>
	  </div>
	  
	  <div class="form-group">
	      <!--- <div class="label">
	           <label>性别：</label>
	       </div>
	       <div class="field" id="" name="" style="padding-top:8px;"> 
	            男 <input name="sex" type="radio" value="男"/>
	            女 <input name="sex" type="radio" value="女"/>
	       </div>-->
		   
		   <div class="label">
		     <label>添加性别：</label>
		   </div>
		   <div class="field">
		     <input type="text" class="input w50" value="" name="sex" id="sex" />
		     <div class="tips"> </div>
		   </div>
	   </div>
	

      <div class="form-group">
          <div class="label">
            <label>个人照片</label>
          </div>
          <div class="field">
            <input type="file" multiple="multiple" class="input w50" id="phone_url" name="phone_url"/>
            <div class="tips"></div>
          </div>
      </div>
	  
	  <div class="form-group">
	    <!--<div class="label">
	      <label>选择学院：</label>
	    </div>
	    <div class="field">
	      <select name="college_name" id="college_name" class="input w50">
	        <option value="">请选择分类</option>
	         <option value="软件学院">软件学院</option>
	  	     <option value="人文学院">人文学院</option>
	      </select>
	  	 <span style="margin-left: 10px; color: red;">*</span>
	      <div class="tips"></div>
	    </div>
		-->
		<div class="label">
		  <label>添加学院：</label>
		</div>
		<div class="field">
		  <input type="text" class="input w50"  name="college_name" id="college_name" data-validate="required:请输入添加人的性别" />
		  <span style="margin-left: 10px; color: red;">*</span>
		  <div class="tips"> </div>
		</div>
		
	  </div>
      
        <div class="form-group">
          <!--<div class="label">
            <label>选择身份类型：</label>
          </div>
          <div class="field">
            <select name="type" id="type" class="input w50">
              <option value="">请选择分类</option>
               <option value="管理员">管理员</option>
			   <option value="普通老师">普通老师</option>
            </select>
			 <span style="margin-left: 10px; color: red;">*</span>
            <div class="tips"></div>
          </div>
		  -->
		  <div class="label">
		    <label>添加类别 0 管理 1 老师：</label>
		  </div>
		  <div class="field">
		    <input type="text" class="input w50"  name="type" id="type" />
		    <span style="margin-left: 10px; color: red;">*</span>
		    <div class="tips"> </div>
		  </div>
        </div>
     
	 <div class="form-group">
	   <div class="label">
	     <label>备注：</label>
	   </div>
	   <div class="field">
	     <input type="text" class="input w50" value="" name="remark" id="remark"  />
	     <div class="tips"> </div>
	   </div>
	 </div>
   
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="button bg-main icon-check-square-o" type="button" id="button bg-main icon-check-square-o" onclick="check1()"> 提交</button>
        </div>
      </div>
    </form>
  </div>
</div>

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
	    function check1(){
		//var sex1= $("input[name='sex']:checked(1)").val();
	    var name = document.getElementById("name").value;
	    var password1 = document.getElementById("password1").value;
	    var password = document.getElementById("password").value;
		var tno = document.getElementById("tno").value;
		var professional = document.getElementById("professional").value;
		var sex = document.getElementById("sex").value;
	//	var phone_url = document.getElementById("phone_url").value;
		var college_name = document.getElementById("college_name").value;
		var type = document.getElementById("type").value;
	    var remark = document.getElementById("remark").value;
	    var phone_url = document.getElementById('phone_url').files[0];
		//console.log("名字"+name+"密码"+password+"公号"+tno+"职称"+professional+"性别"+sex+"照片"+phone_url+"学院"+college_name+"类型"+type+"备注"+remark);
		 // json1=[{name:name,password:password,tno:tno,professional:professional,sex:sex,phone_url:phone_url,college_name:college_name,type:type,remark:remark}]
			// var json2 = JSON.stringify(json1);
	    if(tno == null || tno == ""){
	        alert("工号不能为空");
	        return;
	    }
		if(tno.length !=11){
		    alert("工号为11位请输入11位");
		    return;
		}
	    if(name == null || name == ""){
	        alert("名字不能为空");
	        return;
	    }
	    if(password1 == null || password1 == ""){
	        alert("请再输入密码");
	        return;
	    }
		if(password == null || password == ""){
		    alert("请输入密码");
		    return;
		}
		if(password1 != password ){
		    alert("两次密码不一样");
		    return;
		}
		if(college_name == null || college_name == ""){
		    alert("请选择学院");
		    return;
		}
		if(type == null || type == ""){
		    alert("请选择类型");

		    return;
		}
            var formData = new FormData();
		// phone_url.append("classIcon",fileobj);
		// phone_url.append("classIcon",fileobj);
			//用form 表单直接 构造formData 对象; 就不需要下面的append 方法来为表单进行赋值了。
			//var formData = new FormData($("#uploadForm")[0]);
            formData.append("name",name);
            formData.append("password",password);
            formData.append("tno",tno);
            formData.append("professional",professional);
            formData.append("sex",sex);
            formData.append("phone_url",phone_url);
            formData.append("college_name",college_name);
            formData.append("type",type);
            formData.append("remark",remark);
            console.log(typeof(phone_url));
            console.log(phone_url);
            console.log(formData);
            var arry = $("#form-x").serializeArray();//序列化表单
            var obj = {};//分配内存空间
            for (var i = 0; i < arry.length; i++) {//数据类型为"自定义类的字段名=数据"后台会自动对数据进行匹配
                obj[arry[i].name] = arry[i].value;
            }
	    $.ajax({
            type:"POST",
           // dataType:"json",
            url:"/workview/superviseadd1",
            processData : false,
            contentType : false,
            cache:false,
            async: false,
	        data:formData,
	        success:function(data){
	                console.log(data);
	                if(data.status==401){
	                    alert("熔断开启，系统异常");
	                    window.location.href="login.html";
	                    return;
	                }
	                if(data.status==200) {
	                    localStorage.setItem("supervise",data.data);
	                    window.location.href="adminlist.html";
	                    return;
	                }
	                if(data.status==500) {
	                    alert("添加失败");
	                    window.location.href="adminlist.html";
	                    return;
	                }
	                 if(data.status==null) {
	                    alert("添加异常");
	                    window.location.href="adminlist.html";
	                    return;
	                 }
	        },
	        error:function(XMLHttpRequest,textStatus) {
	            if (textStatus === 'timeout') {
	                alert('請求超時');
	                setTimeout(function () {
	                    alert('重新请求');
	                }, 2000);
	            }
	           // window.location.href="login.html";
                alert("系统异常ajax失败");
	        }
	
	    });
	
	}
	
	
</script>
</body>
</html>